package com.ljw.test.model;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.ToMany;
import org.greenrobot.greendao.annotation.Unique;

import java.util.List;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.DaoException;
import com.ljw.test.dao.DaoSession;
import com.ljw.test.dao.ChildDao;
import com.ljw.test.dao.ParentDao;

@Entity
public class Parent {
    @Id(autoincrement = true)
    Long id;

    @Unique
    String parent;

    @ToMany(referencedJoinProperty = "parentId")
    List<Child> childList;

    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;

    /** Used for active entity operations. */
    @Generated(hash = 936059064)
    private transient ParentDao myDao;

    @Generated(hash = 1972230622)
    public Parent(Long id, String parent) {
        this.id = id;
        this.parent = parent;
    }

    @Generated(hash = 981245553)
    public Parent() {
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getParent() {
        return this.parent;
    }

    public void setParent(String parent) {
        this.parent = parent;
    }

    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 1192159186)
    public List<Child> getChildList() {
        if (childList == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            ChildDao targetDao = daoSession.getChildDao();
            List<Child> childListNew = targetDao._queryParent_ChildList(id);
            synchronized (this) {
                if (childList == null) {
                    childList = childListNew;
                }
            }
        }
        return childList;
    }

    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 20549044)
    public synchronized void resetChildList() {
        childList = null;
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 1321580708)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getParentDao() : null;
    }

    @Override
    public String toString() {
        return "Parent{" +
                "id=" + id +
                ", parent='" + parent + '\'' +
                ", childList=" + childList +
                '}';
    }
}
